package MethodReturn;

/*
 * 方法的返回值可以是什么类型的
 *
 * 1、基本类型
 * 2、数组
 * 3、字符串
 * 4、自定义的类
 * */
public class MethodReturn {
    public static void main(String[] args) {
        int result1 = method1();
        System.out.println(result1);
        System.out.println("**********************");

        int[] result2 = method2();
        System.out.println(result2[0] + result2[1]);
        System.out.println("**********************");

        String result3 = method3();
        System.out.println(result3.replace("o", "*"));
        System.out.println("**********************");
        Student result4 = method4();
        System.out.println("姓名:" + result4.getName() + ",年龄:" + result4.getAge());
        System.out.println("**********************");


    }

    //    使用基本数据类型作为返回值
    public static int method1() {
        int num = 100;
        return num;
    }

    //使用数组作为返回值
    public static int[] method2() {
        int[] array = {10, 20, 30};
        return array;
    }

    //    使用字符串作为返回值
    public static String method3() {
        String str = "hello";
        return str;
    }

    //    使用自定义的类作为方法的返回值
    public static Student method4() {
//        System.out.println("姓名:" + stu.getName() + ",年龄:" + stu.getAge());
        Student stu = new Student("迪丽热巴", 20);
        return stu;
    }

    static class Student {
        private String name;
        private int age;

        public Student() {
        }

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        public String getName() {
            return name;
        }
    }
}
